package com.yj.suncity.utis;


import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ListView;

public class PagerListView extends ListView {
	private GestureDetector mGestureDetector;
//	View.OnTouchListener mGestureListener;
	public PagerListView(Context context) {
		super(context);
		init();
	}

	public PagerListView(Context context, AttributeSet attrs) {
		super(context, attrs);
		
		init();
	}

	public PagerListView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init();
	}
	public void init(){
		mGestureDetector = new GestureDetector(new YScrollDetector());
		setFadingEdgeLength(0);
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
//		if(ev.getAction() == MotionEvent.ACTION_UP){
//   		 canScroll = true;
//   	}
		 super.onInterceptTouchEvent(ev);
		return mGestureDetector.onTouchEvent(ev);
	}

	class YScrollDetector extends SimpleOnGestureListener {
		@Override
		public boolean onScroll(MotionEvent e1, MotionEvent e2,
				float distanceX, float distanceY) {
	/*		if (distanceY != 0 && distanceX != 0) {

			}
			if (Math.abs(distanceY) >= Math.abs(distanceX)) {
				return true;
			}
			return false;*/
//			Log.d("", e1.getX()+"====1===="+e1.getY());
//			Log.d("", e2.getX()+"====2===="+e2.getY());
			if (Math.abs(e1.getX() - e2.getX())>Math.abs(e1.getY()-e2.getY())) {
				return false;
			}else{
				return true;
			}
//            if (canScroll)
//                if (Math.abs(distanceY) >= Math.abs(distanceX))
//                        canScroll = true;
//                else
//                        canScroll = false;
		}
	}
}